{% extends "base.html" %}

{% block body %}
<div id="creds_div" style="margin-top:5px;max-height:calc(90vh)">
    <div class="card border border-dark shadow bg-card-body">
        <div class="card-header bg-header text-white" >
            <h2 style="display:inline-block"><span class="operator">Credentials</span></h2>
            <button style="float:right" class="btn btn-md btn{{config['outline-buttons']}}success" @click="register_new_credential()"><i class="fas fa-plus"></i> Credential</button>
        </div>
            <table class="table table-striped {{config['table-color']}} border border-dark" style="margin-bottom:0">
                <tr>
                    <th style="width:3rem"></th>
                    <th onclick="sort_table(this)" style="text-align:left;width:5rem"><b>Type</b></th>
                    <th onclick="sort_table(this)" style="width:10rem"><b>Account</b></th>
                    <th onclick="sort_table(this)" style="width:10rem;"><b>Realm</b></th>
                    <th onclick="sort_table(this)"><b>Credential</b></th>
                    <th onclick="sort_table(this)" style="width:15rem"><b>Task</b></th>
                    <th onclick="sort_table(this)" style="width:20rem"><b>Comment</b></th>
                    <th style="width:2rem"><b>Edit</b></th>
                </tr>
                <tr v-for="(c,i) in credentials" :key="c.timestamp">
                    <td style="text-align:center">
                        <button class="btn btn-sm btn{{config['outline-buttons']}}danger" @click="remove_credential(c)"><i class="fas fa-trash-alt"></i></button>
                    </td>
                    <td>[[c.type]]</td>
                    <td>[[c.account]]</td>
                    <td>[[c.realm]]</td>
                    <td style="word-break: break-all">[[c.credential]]</td>
                    <td v-if="!c.hasOwnProperty('task')">Manual Entry by [[c.operator]]</td>
                    <td v-else><a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + c.task" target="_blank">[[c.task]]</a> - [[c.task_command]]</td>
                    <td>[[c.comment]]</td>
                    <td style="text-align:center">
                        <button class="btn btn-sm btn{{config['outline-buttons']}}warning" @click="edit_credential(c)"><i class="fas fa-edit"></i></button>
                    </td>
                </tr>
            </table>
    </div>
</div>
<!-- THIS IS OUR MODAL FOR CREATING A CREDENTIAL -->
<div class="modal fade" id="createCredentialModal" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>Register a new credential for the current operation</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-body">
                <table class="table table-striped {{config['table-color']}}">
                    <tr>
                        <td>Credential Type&nbsp;</td>
                        <td><select id="createCredentialType" class="form-control">
                            <option value="plaintext">plaintext</option>
                            <option value="hash">hash</option>
                            <option value="key">api or backup key</option>
                            <option value="certificate">certificate</option>
                            <option value="ticket">ticket</option>
                            <option value="hex">hex</option>
                        </select></td>
                    </tr>
                    <tr>
                        <td>Account: </td>
                        <td><input class="form-control" type="text" size="60" id="createCredentialAccount"></td>
                    </tr>
                    <tr>
                        <td>Realm: </td>
                        <td><input class="form-control" type="text" size="60" id="createCredentialRealm"></td>
                    </tr>
                    <tr>
                        <td>Comment: </td>
                        <td><input class="form-control" type="text" size="60" id="createCredentialComment"></td>
                    </tr>
                    <tr>
                        <td>Credential: </td>
                        <td><textarea class="form-control" cols="60" rows="30" id="createCredentialCredential"></textarea></td>
                    </tr>
                </table>
              </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button class="btn btn{{config['outline-buttons']}}primary" data-dismiss="modal" id="createCredentialSubmit">Create</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR CREATING A CREDENTIAL -->
{% endblock %}
{% block scripts %}
{% include "credentials.js" %}
{% endblock %}

{% block body_config %}

{% endblock %}